﻿/**
* @description  Class to test SWF playback.
*/
package test {
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;

	import com.moke.media.controllers.SWFController;
	import com.moke.media.displays.SWFDisplay;
	import com.moke.media.events.MediaEvent;
	
	[SWF(width=550, height=400)]

	public class SWFTest extends Sprite {

		private var _swfController:SWFController;
		private var _swfDisplay:SWFDisplay;
		
		/**
		* @description  Constructor.
		*/
		public function SWFTest() {
			init();
		}
		
		/**
		* @description  Creates controller and display, then loads video.
		*/
		private function init():void {
			_swfController = new SWFController();
			_swfController.addEventListener(Event.INIT, mediaInit, false, 0, true);
			_swfController.addEventListener(MediaEvent.COMPLETE, mediaComplete, false, 0, true);

			_swfDisplay = new SWFDisplay();
			addChild(_swfDisplay);
			_swfDisplay.x = 115;
			_swfDisplay.y = 80;
			_swfDisplay.displayWidth = 320;
			_swfDisplay.displayHeight = 240;
			_swfDisplay.setController(_swfController);

			_swfController.loadMedia("../assets/bookworm.swf");

			stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown, false, 0, true);
		}
		
		/**
		* @description  Event handler for when media starts.
		*
		* @param  pEvent  Event fired by MediaController.
		*/
		private function mediaInit(pEvent:Event):void {
			trace("SWF init");
		}

		/**
		* @description  Event handler for when media completes.
		*
		* @param  pEvent  Event fired by MediaController.
		*/
		private function mediaComplete(pEvent:MediaEvent):void {
			trace("SWF complete");
		}

		/**
		* @description  Event handler for when stage is clicked.
		*
		* @param  pEvent  Event fired by Mouse.
		*/
		private function mouseDown(pEvent:MouseEvent):void {
			_swfController.pauseMedia(!_swfController.paused);
		}

	}
	
}